class Solution:
    def romanToInt(self, s: str) -> int:
        # 定义映射表
        roman_map = {
            'I': 1,
            'V': 5,
            'X': 10,
            'L': 50,
            'C': 100,
            'D': 500,
            'M': 1000
        }
        sum = 0
        pre_num = 0
        for i in reversed(s):
            value = roman_map[i]
            if pre_num > value:
               sum -= value
            else:
                sum += value
            pre_num = value
        return sum
print(Solution().romanToInt("VI"))